package com.supreme.common.utils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.function.Consumer;

public class FilePathUtils {

    public static final String userDirString = System.getProperty("user.dir");

    public static final Path tempDataPath = Paths.get(userDirString, "/temp-data");

    public static void createDirectory(Path path, Consumer<Path> consumer) {
        try {
            if (!Files.exists(path)) {
                Files.createDirectory(path);
                consumer.accept(path);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void createDirectory(Path path) {
        FilePathUtils.createDirectory(path, null);
    }

    public static void createFile(Path path, Consumer<Path> consumer) {
        try {
            if (!Files.exists(path)) {
                Files.createFile(path);
                consumer.accept(path);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void createFile(Path path) {
        FilePathUtils.createFile(path, null);
    }
}
